home *** CD-ROM | disk | FTP | other *** search
- /*
- * Source machine generated by GadToolsBox V2.0b
- * which is (c) Copyright 1991-1993 Jaba Development
- *
- * GUI Designed by : Michael D. Bayne
- */
-
- #include <exec/types.h>
- #include <intuition/intuition.h>
- #include <intuition/classes.h>
- #include <intuition/classusr.h>
- #include <intuition/imageclass.h>
- #include <intuition/gadgetclass.h>
- #include <libraries/gadtools.h>
- #include <graphics/displayinfo.h>
- #include <graphics/gfxbase.h>
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/gadtools_protos.h>
- #include <clib/graphics_protos.h>
- #include <clib/utility_protos.h>
- #include <string.h>
- #include <clib/diskfont_protos.h>
-
- #include "Life.h"
-
- struct Screen *Scr = NULL;
- UBYTE *PubScreenName = "Workbench";
- APTR VisualInfo = NULL;
- struct Window *LifeWnd = NULL;
- struct Gadget *LifeGList = NULL;
- struct IntuiMessage LifeMsg;
- struct Gadget *LifeGadgets[6];
- UWORD LifeLeft = 0;
- UWORD LifeTop = 12;
- UWORD LifeWidth = 240;
- UWORD LifeHeight = 59;
- UBYTE *LifeWdt = (UBYTE *)"Life Prefs";
- struct TextAttr *Font, Attr;
- UWORD FontX, FontY;
- UWORD OffX, OffY;
- struct TextFont *LifeFont = NULL;
-
- UWORD LifeGTypes[] = {
- SLIDER_KIND,
- BUTTON_KIND,
- BUTTON_KIND,
- SLIDER_KIND,
- SLIDER_KIND,
- BUTTON_KIND
- };
-
- struct NewGadget LifeNGad[] = {
- 82, 2, 119, 13, (UBYTE *)"_Size", NULL, GD_BSIZE, PLACETEXT_LEFT, NULL, (APTR)BSIZEClicked,
- 8, 45, 66, 12, (UBYTE *)"_Ok", NULL, GD_OK, PLACETEXT_IN, NULL, (APTR)OKClicked,
- 167, 45, 66, 12, (UBYTE *)"_Cancel", NULL, GD_CANCEL, PLACETEXT_IN, NULL, (APTR)CANCELClicked,
- 82, 17, 120, 12, (UBYTE *)"_Generations", NULL, GD_GENS, PLACETEXT_LEFT, NULL, (APTR)GENSClicked,
- 82, 31, 120, 12, (UBYTE *)"_Density", NULL, GD_DENSE, PLACETEXT_LEFT, NULL, (APTR)DENSEClicked,
- 87, 45, 66, 12, (UBYTE *)"_Test", NULL, GD_TEST, PLACETEXT_IN, NULL, (APTR)TESTClicked
- };
-
- ULONG LifeGTags[] = {
- (GTSL_Min), 5, (GTSL_Max), 40, (GTSL_Level), 20, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
- (GT_Underscore), '_', (TAG_DONE),
- (GT_Underscore), '_', (TAG_DONE),
- (GTSL_Min), 5, (GTSL_Max), 999, (GTSL_Level), 150, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
-
-
- (GTSL_Min), 1, (GTSL_Max), 99, (GTSL_Level), 16, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
- (GT_Underscore), '_', (TAG_DONE)
- };
-
- static UWORD ComputeX( UWORD value )
- {
- return(( UWORD )((( FontX * value ) + 3 ) / 6 ));
- }
-
- static UWORD ComputeY( UWORD value )
- {
- return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
- }
-
- static void ComputeFont( UWORD width, UWORD height )
- {
- Forbid();
- Font = &Attr;
- Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
- Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
- FontX = GfxBase->DefaultFont->tf_XSize;
- Permit();
-
- OffX = Scr->WBorLeft;
- OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
-
- if ( width && height ) {
- if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
- goto UseTopaz;
- if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
- goto UseTopaz;
- }
- return;
-
- UseTopaz:
- Font->ta_Name = (STRPTR)"topaz.font";
- FontX = FontY = Font->ta_YSize = 8;
- }
-
- int SetupScreen( void )
- {
- if ( ! ( Scr = LockPubScreen( PubScreenName )))
- return( 1L );
-
- ComputeFont( 0, 0 );
-
- if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
- return( 2L );
-
- return( 0L );
- }
-
- void CloseDownScreen( void )
- {
- if ( VisualInfo ) {
- FreeVisualInfo( VisualInfo );
- VisualInfo = NULL;
- }
-
- if ( Scr ) {
- UnlockPubScreen( NULL, Scr );
- Scr = NULL;
- }
- }
-
- int HandleLifeIDCMP( void )
- {
- struct IntuiMessage *m;
- int (*func)();
- BOOL running = TRUE;
-
- while( m = GT_GetIMsg( LifeWnd->UserPort )) {
-
- CopyMem(( char * )m, ( char * )&LifeMsg, (long)sizeof( struct IntuiMessage ));
-
- GT_ReplyIMsg( m );
-
- switch ( LifeMsg.Class ) {
-
- case IDCMP_REFRESHWINDOW:
- GT_BeginRefresh( LifeWnd );
- GT_EndRefresh( LifeWnd, TRUE );
- break;
-
- case IDCMP_VANILLAKEY:
- running = LifeVanillaKey();
- break;
-
- case IDCMP_GADGETUP:
- case IDCMP_GADGETDOWN:
- func = ( void * )(( struct Gadget * )LifeMsg.IAddress )->UserData;
- running = func();
- break;
- }
- }
- return( running );
- }
-
- int OpenLifeWindow( void )
- {
- struct NewGadget ng;
- struct Gadget *g;
- UWORD lc, tc;
- UWORD wleft, wtop, ww, wh;
-
- ComputeFont( LifeWidth, LifeHeight );
-
- ww = ComputeX( LifeWidth );
- wh = ComputeY( LifeHeight );
-
- wleft = ( Scr->Width - ww )/2 - Scr->WBorRight;
- wtop = ( Scr->Height - wh - Scr->WBorBottom*2 - Font->ta_YSize )/2;
-
- if ( ! ( LifeFont = OpenDiskFont( Font )))
- return( 5L );
-
- if ( ! ( g = CreateContext( &LifeGList )))
- return( 1L );
-
- for( lc = 0, tc = 0; lc < Life_CNT; lc++ ) {
-
- CopyMem((char * )&LifeNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
-
- ng.ng_VisualInfo = VisualInfo;
- ng.ng_TextAttr = Font;
- ng.ng_LeftEdge = OffX + ComputeX( ng.ng_LeftEdge );
- ng.ng_TopEdge = OffY + ComputeY( ng.ng_TopEdge );
- ng.ng_Width = ComputeX( ng.ng_Width );
- ng.ng_Height = ComputeY( ng.ng_Height);
-
- LifeGadgets[ lc ] = g = CreateGadgetA((ULONG)LifeGTypes[ lc ], g, &ng, ( struct TagItem * )&LifeGTags[ tc ] );
-
- while( LifeGTags[ tc ] ) tc += 2;
- tc++;
-
- if ( NOT g )
- return( 2L );
- }
-
- if ( ! ( LifeWnd = OpenWindowTags( NULL,
- WA_Left, wleft,
- WA_Top, wtop,
- WA_Width, ww + OffX + Scr->WBorRight,
- WA_Height, wh + OffY + Scr->WBorBottom,
- WA_IDCMP, SLIDERIDCMP|BUTTONIDCMP|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
- WA_Flags, WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
- WA_Gadgets, LifeGList,
- WA_Title, LifeWdt,
- WA_ScreenTitle, "Life Prefs",
- WA_AutoAdjust, TRUE,
- WA_PubScreenFallBack, TRUE,
- TAG_DONE )))
- return( 4L );
-
- GT_RefreshWindow( LifeWnd, NULL );
-
- return( 0L );
- }
-
- void CloseLifeWindow( void )
- {
- if ( LifeWnd ) {
- CloseWindow( LifeWnd );
- LifeWnd = NULL;
- }
-
- if ( LifeGList ) {
- FreeGadgets( LifeGList );
- LifeGList = NULL;
- }
-
- if ( LifeFont ) {
- CloseFont( LifeFont );
- LifeFont = NULL;
- }
- }
-
-